const CourseTabModel = require('../db/models/courseTab');
//import model


class CourseTabServer {
  async addCourseTabData (data) {
    //检查cid是否存在 check cid is existed
    const cid = data.cid; //修改
    const result = await CourseTabModel.findOne({where: { cid }}); //修改
    //判断 check
    if (result) {
      //更新 update
      return await CourseTabModel.update(data, {where: { cid }})
    }else {
      //创建 create
      return await CourseTabModel.create(data);
    }
  }

  
  async getCourseFieldData () {
    const data = await CourseTabModel.findAll({
      attributes: {
        exclude: ['cid', 'createdAt', 'updatedAt']
      }
    })
    return data;
  }
}

module.exports = new CourseTabServer();